import 'package:flutter/material.dart';
import 'package:flutter_scan_tool/page/home_page.dart';
import 'package:flutter_scan_tool/widget/animated_background.dart';

class SplashPage extends StatefulWidget {

  SplashPage({Key? key}):super(key: key);

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _SplashPageState();
  }

}

class _SplashPageState extends State<SplashPage> with TickerProviderStateMixin {
  late AnimationController _logoController;
  late CurvedAnimation _logoAnimation;
  late Tween _scaleTween;

  @override
  void initState() {
    super.initState();
    _scaleTween = Tween(begin: 0, end: 1);
    _logoController =
    AnimationController(vsync: this, duration: const Duration(milliseconds: 3000))
      ..drive(_scaleTween);
    Future.delayed(const Duration(milliseconds: 500), () {
      _logoController.forward();
    });
    _logoAnimation =
        CurvedAnimation(parent: _logoController, curve: Curves.easeOutQuart);

    _logoController.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        Future.delayed(const Duration(milliseconds: 500), () {
          goPage();
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Positioned.fill(child: AnimatedBackground()),
        Positioned.fill(
          child: SizedBox(
            height: double.infinity,
            width: double.infinity,
            child: ScaleTransition(
              scale: _logoAnimation,
              child: Hero(
                tag: 'logo',
                child: Image.asset('image/logo.png')
                // SvgPicture.asset('image/back.svg'),
              ),
            ),
          ),
        ),
      ],
    );
  }

  void goPage() async {
    Navigator.of(context).push(MaterialPageRoute(builder: (context){
      return const HomePage();
    }));
  }
}

@override
void dispose() {}